/**
 * @file uva/11020/main
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 5/28/2022 09:57:10
 **/

#include <cstring>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define S (siz[ls[rt]] + 1)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int N = 2e4 + 10;
int t, n, ord, rt, siz[N];
int k1[N], k2[N], ls[N], rs[N];
void lrot(int &x) {
  int y = ls[x];
  ls[x] = rs[y], rs[y] = x;
  siz[y] = siz[x];
  siz[x] = siz[ls[x]] + siz[rs[x]] + 1;
  x = y;
  return;
}
void rrot(int &x) {
  int y = rs[x];
  rs[x] = ls[y], ls[y] = x;
  siz[y] = siz[x];
  siz[x] = siz[ls[x]] + siz[rs[x]] + 1;
  x = y;
  return;
}
int rankx(int k, int x, int y) {
  if (!k) return 0;
  if (x > k1[k] || (x == k1[k] && y >= k2[k]))
    return siz[ls[k]] + rankx(rs[k], x, y) + 1;
  else
    return rankx(ls[k], x, y);
}
int ranky(int k, int x, int y) {
  if (!k) return 1;
  if (y < k2[k] || (y == k2[k] && x <= k1[k]))
    return siz[ls[k]] + ranky(rs[k], x, y) + 1;
  else
    return ranky(ls[k], x, y);
}
void splay(int x, int &y) {
  int o = siz[ls[y]] + 1;
  if (x == o) return;
  if (x > o) {
    splay(x - o, rs[y]);
    rrot(y);
  } else {
    splay(x, ls[y]);
    lrot(y);
  }
}
void prepare() {
  memset(ls, 0, sizeof(ls));
  memset(rs, 0, sizeof(rs));
  rt = 1, k1[1] = -1, k2[1] = INF;
  rs[rt] = 2, siz[1] = 2, ord = 2;
  k1[2] = INF, k2[2] = -1, siz[2] = 1;
}
int main() {
  // High rating and good luck!
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> t;
  for (int x, y, k = 1; k <= t; ++k) {
    cin >> n;
    prepare();
    cout << "Case #" << k << ":\n";
    while (n--) {
      cin >> x >> y;
      int l = rankx(rt, x, y);
      int r = ranky(rt, x, y);
      if (l < r) {
        splay(l, rt), splay(r - S, rs[rt]);
        int p = ls[rs[rt]] = ++ord, q = rs[rt];
        k1[p] = x, k2[p] = y, siz[p] = 1;
        siz[q] = siz[rs[q]] + 2;
        siz[rt] = siz[ls[rt]] + siz[q] + 1;
      } else {
        // pass
      }
      cout << siz[rt] - 2 << endl;
    }
    if (k < t) cout.put('\n');
  }
  return 0;
}
